<?php
/**
 * Logs
 * 
 * @copyright inovia
 * @package oolime_core   
 * @todo fix log display problems 
 */
class Logs{
  public $logType;
  public $logFileName;

  public function __construct(){
    global $configLogType;
    global $configLogFileName;
    $this->logType      = $configLogType;
    $this->logFileName  = $configLogFileName;
  }

	/**
	 * Logs a message with a priority
	 * @param syslog priority
	 * @param string the log message	 
	 */   	
	public function log($priority,$message){
	  if($this->logType == "syslog"){
      syslog($priority,$message);
	  }
	  if($this->logType == "file"){
      $logFile = fopen($this->logFileName,"a+");
      fputs($logFile,"[".$priority."] [".date('c')."]".$message."\n");
      fclose($logFile);
    }
	}

	public function logDebug($message){
    $this->log(LOG_DEBUG,$message);
  }
  public function logInfo($message){
    $this->log(LOG_INFO,$message);
  }
  public function logNotice($message){
    $this->log(LOG_NOTICE,$message);
  }
  public function logWarning($message){
    $this->log(LOG_WARNING,$message);
  }
  public function logError($message){
    $this->log(LOG_ERR,$message);
  }
  public function logCritical($message){
    $this->log(LOG_CRIT,$message);
  }
  public function logAlert($message){
    $this->log(LOG_ALERT,$message);
  }
  public function logEmergency($message){
    $this->log(LOG_EMERG,$message);
  }
	
	
	/**
	 * Purges the log file
	 * @todo implement	 
	 */   	
	public function purgeLogFile(){

	}
	
	
	public function getLogs($pattern,$name){
	 /**
   $root = new DOMElement($name);
	 $this->response->doc->appendChild($root);
	   foreach (glob($pattern) as $filename) {
	     $Node=$this->response->doc->createElement("entry");
	     
	     $NodeName=$this->response->doc->createElement("name");
	     $NodeValueName=$this->response->doc->createTextNode($filename);
	     $NodeName->appendChild($NodeValueName);
	     $Node->appendChild($NodeName);
	     
	     $NodeTime=$this->response->doc->createElement("date");
	     $NodeValueTime=$this->response->doc->createTextNode(date("Y h:i:s A",filemtime($filename)));
	     $NodeTime->appendChild($NodeValueTime);
	     $Node->appendChild($NodeTime);
	     
	     $root->appendChild($Node);
	   }
	   $this->response->add($root);**/
	}
}


?>
